﻿using System;
using System.Collections.Generic;
using System.Text;

using ChaosEngine.EngineCore;
using System.IO;
using CSScriptLibrary;
using System.Reflection;
namespace ChaosEngine.EngineCore.JS
{
    public class UserCode
    {
        public Assembly Asm;
        public string Code
        {
        
            get;
            set;
        
        }
        
        public UserCode(string addr)
        {

             addr = FSHelper.AddrToPath(addr);
             Code = File.ReadAllText(addr);
             Asm = CSScript.LoadCode(Code);
           

        }

        /// <summary>
        /// use "*" to create the first class in the script, useful if you don't know the name at compile-time.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public dynamic CreateClass(string name){
            return Asm.CreateObject(name);
        }

    }

  
}
